package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a17376052_wcp_finaltest.R;

import java.util.List;

import entire.Fruit;

public class FruitAdapter extends ArrayAdapter<Fruit> {
    private int resourceId;
    private List<Fruit> fruits;

    public FruitAdapter(Context context, int textViewResourceId, List<Fruit> fruits){
        super(context, textViewResourceId, fruits);
        this.resourceId = textViewResourceId;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        Fruit fruit = getItem(position);
        View view = LayoutInflater.from(this.getContext()).inflate(resourceId, null);
        ImageView fruitImage = (ImageView)view.findViewById(R.id.fruit_image);
        TextView fruitName = (TextView)view.findViewById(R.id.fruit_name);

        fruitImage.setImageResource(fruit.getImageId());
        fruitName.setText(fruit.getName());

        return view;
    }
}
